angular.module('app').config(($stateProvider) => {

    $stateProvider.state('app.slide-box', {
        url         : '/slide-box',
        label       : 'Side Box',
        controller  : 'app.slide-box',
        controllerAs: '$ctrl',
        templateUrl : 'view/app/slide-box/slide-box.html'
    });
}).controller('app.slide-box', function ($scope) {
    let ctrl = this, random;
    ctrl.current = 'slides';
    ctrl.sliders = genArray(3);
    // 配置参照 http://idangero.us/swiper/api/#.V9df5oZ96Hs
    ctrl.options = {
        loop              : false,
        effect            : 'slide', // "slide", "fade", "cube", "coverflow" "flip"
        speed             : 500,
        autoplay          : 3000,
        autoplayStopOnLast: false
    };
    ctrl.dynamicallyChangeData = ()=> {
        // 2~6 的随机数
        random = parseInt(Math.random() * (7 - 2)) + 2;
        ctrl.sliders = genArray(random);
        if (ctrl.slider) {
            ctrl.slider.updateLoop();
        }
    };
    $scope.$on('$ionicSlides.slideChangeStart', ()=> {
        console.log('$ionicSlides.slideChangeStart');
    });
    $scope.$on('$ionicSlides.slideChangeEnd', ()=> {
        console.log('$ionicSlides.slideChangeEnd');
    });
    $scope.$on('$ionicSlides.sliderInitialized', (e, data)=> {
        console.log('$ionicSlides.sliderInitialized');
        console.log(e);
        console.log(data);
        ctrl.slider = data.slider;
    });
    
    /////////////////////////////////////////////////
    // 注意: ion-slide-box 在后续的 ionic 版本中会被移除, 故不使用.
    /////////////////////////////////////////////////

    function genArray(num) {
        return [...new Array(num).keys()];
    }
});